package com.huoshan.im.server.utils;

import com.huoshan.im.server.config.properties.SettingConfig;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 火山九日
 * @version 1.0
 * @date 创建时间：2021/8/3 11:18
 * @desc 飞书告警工具
 */
@Slf4j
@Component
@AllArgsConstructor
public class FeiShuUtil {

    public static final String TAG = "【提提电竞IM系统】 ";

    private final RestTemplate restTemplate;
    private final SettingConfig settingConfig;

    public void sendMsg(String msg) {

        Map<String, Object> text = new HashMap<>();
        text.put("text", TAG + msg);
        Map<String, Object> params = new HashMap<>();
        params.put("msg_type", "text");
        params.put("content", text);

        try {
            String ret = restTemplate.postForObject(settingConfig.getFeishuWebhook(), params, String.class);

            log.debug("发送飞书告警, ret: {}", ret);

        } catch (Exception e) {
            e.printStackTrace();
            log.error("发送飞书告警失败, msg: {}", msg);
        }

    }

}
